-
Notifications
You must be signed in to change notification settings - Fork 698
Add custom error handling for non-git repositories with initialization option #10483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
3af024b
to
cd0e2c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I processed the PR to be usable, but it needs frontend work.
The basis already works and isn't bad at all.

Screen.Recording.2025-09-29.at.06.02.53.mov
But to truly work, it needs some finesse that I unfortunately cannot provide.
Maybe a low-hanging fruit to pick if it's not too complicated to actually do.
CC @PavelLaptev and @estib-vega
PS: the PR is based on this message on Discord.
#[tauri::command] | ||
#[instrument(err(Debug))] | ||
pub fn init_git_repository(path: String) -> Result<(), Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function trivially would have to be moved to but-api
.
message: | ||
'The selected directory is not a Git repository. Would you like to initialize one?', | ||
style: 'warning', | ||
extraAction: { | ||
label: 'Initialize Repository', | ||
onClick: async (dismiss) => { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the main difficulty: initialising and re-adding the project from here to get a project id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me take a look!
@Byron, just to clarify: That warning pop-up is shown when the backend hits: https://github.com/gitbutlerapp/gitbutler/blob/master/crates/gitbutler-project/src/controller.rs#L100 My understanding is that this is a catch-all response for failing to open a directory. So, just wanted to confirm that that can only mean that the repository is not initialized. Otherwise, we'd be offering a 'false' fix action. |
That's a very good point - right now it's very 'rough'. Can I add this improvement as second pass on yours?
|
cd0e2c1
to
a860421
Compare
…oject Co-authored-by: Byron <[email protected]>
Move the method for initializing a repository by its path to the shared API module, so that the server can have this as well
When adding a non-git repostory and then chossing to initialize that, the application should correcly add the project
a860421
to
c15f679
Compare
@Byron This effort might need more planning that probably intended. Let me know what you think: The option to initialize a directory as a git repository will lead for the project to be added, but the next thing that the user will see is an error page: ![]() The issue is that no project without a remote can be added to the application (yet) and so it explodes |
We might want to add more methods to address this gracefully, from the application, but that seems to increase the scope of this as bit too much. At this point, we need to design this flow correctly (because this state can already be encountered regardless of whether this changes make it into the application) I'll tag here @PavelLaptev, since we need to make some time to work this flow (IMO we can get away with just displaying a splash screen asking the user to add a remote to their repository from the terminal and pushing). |
In its current state, I'll avoid merging this, since we'd be adding a big pathway into scary cul-de-sac |
I see 😅. I'd say we salvage what's there, I improve the error handling so it's precise, and we merge it as is knowing that soon this will be covered by single-branch mode. Probably once we have improved onboarding to not enforce setting the target branch anyway, we'd want to have an E2E test for this extended flow:
Wonderful :). Also definitely CC @krlvi and @mtsgrd just to be sure this goes in the right direction. |
I'd wait for this to be implemented before merging this, though. I wouldn't like to trade a warning pop-up for a non-actionable full-screen error |
Alright - I got carried away. I will add the error selection now and you can take it over again. |
… false positives.
Here is the commit - and now that I tried it myself I totally understand why we should not just merge this. Screen.Recording.2025-09-30.at.14.20.06.mov |
Thanks @estib-vega Ill check this out |
When users attempt to set a non-git directory as an active project, GitButler now provides a user-friendly experience with an option to initialize a git repository directly from the error dialog.
Problem
Previously, when users tried to open a project in a directory that wasn't a git repository, they would encounter a generic error message with no clear path forward. This created friction in the onboarding experience and left users unsure how to proceed.
Solution
This PR implements a complete solution that:
Detects non-git repositories - Enhanced
set_project_active()
to recognize whengit2::Repository::open()
fails due to missing git structure (error codes:NotFound
,Invalid
,Config
)Provides custom error classification - Added new
NonGitRepository
error code to the error system that maps from backend to frontendOffers guided remediation - Shows a special warning toast with an "Initialize Repository" button instead of a generic error
Safely initializes git repositories - New
init_git_repository()
Tauri command with comprehensive safety checks:Seamless user experience - After successful initialization, automatically retries loading the project
User Flow
Technical Implementation
Backend Changes:
NonGitRepository
variant togitbutler_error::error::Code
set_project_active()
with multiple git2 error code mappinginit_git_repository()
command with write permission validationFrontend Changes:
knownErrors.ts
Safety & Validation
This change maintains full backward compatibility while significantly improving the user experience for a common onboarding scenario. Users can now seamlessly convert any directory into a GitButler-compatible project with a single click.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.